package crud.client.data.authentication;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Authentication implements Serializable, IsSerializable
{
	private boolean isAdmin = false;
	private boolean isModififcationForAll = false;
	private boolean isVisualisationForAll = false;

	private Map<String, Right> tableRightMap = new HashMap<String, Right>();

	public boolean isAdmin()
	{
		return isAdmin;
	}

	public void setAdmin(boolean isAdmin)
	{
		this.isAdmin = isAdmin;
	}

	public boolean isModififcationForAll()
	{
		return isModififcationForAll;
	}

	public void setModififcationForAll(boolean isModififcationForAll)
	{
		this.isModififcationForAll = isModififcationForAll;
	}

	public boolean isVisualisationForAll()
	{
		return isVisualisationForAll;
	}

	public void setVisualisationForAll(boolean isVisualisationForAll)
	{
		this.isVisualisationForAll = isVisualisationForAll;
	}

	public Right getRight(String tableClassName)
	{
		Right right = tableRightMap.get(tableClassName);
		
		if (right != null)
		{
			return right;
		}
		
		if (isAdmin == true || isModififcationForAll)
		{
			return Right.MODIFICATION;
		}
		
		if (isVisualisationForAll == true)
		{
			return Right.VISUALISATION;
		}

		return Right.NONE;
	}

	public void setTableRightSet(Map<String, Right> tableRightSet)
	{
		this.tableRightMap = tableRightSet;
	}
	
	public void addRight(String tableClassName, Right right)
	{
		tableRightMap.put(tableClassName, right);
	}


	
}
